/**
 * 广口瓶,精盐
 */
WideBottle = Widget.extend({
	ctor:function(p){
		this._super();
		p.addChild(this, 5, TAG_WIDE_NODE);
		this.setCascadeOpacityEnabled(true);
		this.init();
	},
	init:function(){
		this.body = new Button(this, 10, TAG_WDIE_BODY, "#bottle/wide.png", this.callback);
		var lid = new Button(this, 10, TAG_WDIE_LID, "#bottle/wide_lid.png", this.callback);
		lid.setPosition(0,40);
		var label = new cc.LabelTTF("精盐",gg.fontName,12);
		label.setColor(cc.color(0,0,0));
		label.setPosition(25, 40);
		this.body.addChild(label, 11);
	},
	addSalt:function(next){
		var salt = new cc.Sprite("#salt5.png");
		salt.setScale(0.7);
		salt.setOpacity(0);
		salt.setPosition(this.body.width * 0.5, 10 + salt.height * 0.5);
		this.body.addChild(salt);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.fadeIn(0.5), cc.callFunc(function(){
				gg.flow.next();
			}, this));
		} else {
			seq = cc.sequence(cc.fadeIn(0.5));
		}
		salt.runAction(seq);
	},
	openLid:function(){
		var ber = cc.bezierBy(1.5,[cc.p(50,70),cc.p(60,-70),cc.p(60,-75)]);
		var rotate = cc.rotateTo(1.5, 180);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,this.func);
		this.getChildByTag(TAG_WDIE_LID).runAction(seq);
	},
	closeLid:function(){
		var lid = this.getChildByTag(TAG_WDIE_LID);
		lid.setSpriteFrame("bottle/wide_lid.png");
		lid.setRotation(180);
		var ber = cc.bezierTo(1.5,[cc.p(60,40),cc.p(50,70),cc.p(0,40)]);
		var rotate = cc.rotateTo(1.5, 0);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,this.func);
		this.getChildByTag(TAG_WDIE_LID).runAction(seq);
	},
	callback:function(p){
		switch(p.getTag()){
			case TAG_WDIE_LID:
				if(gg.flow.flow.action == ACTION_DO1){
					this.openLid();	
				} else if(gg.flow.flow.action == ACTION_DO2){
					this.closeLid();	
				}
				break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
			case TAG_WDIE_LID:
				if(gg.flow.flow.action == ACTION_DO1){
					p.setRotation(0);
					p.setSpriteFrame("bottle/wide_lid2.png");
					gg.flow.next();
				} else if(gg.flow.flow.action == ACTION_DO2){
					this.scheduleOnce(function(){
						gg.flow.next();
					},1.5);	
				}
				break;
		}
	}
});